package br.com.linkideias.model.command.pcc;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.hibernate.Session;

import br.com.linkideias.model.bean.Aluno;
import br.com.linkideias.model.bean.Categoria;
import br.com.linkideias.model.bean.Estatus;
import br.com.linkideias.model.bean.Pcc;
import br.com.linkideias.model.command.InterfaceCommand;
import br.com.linkideias.model.dao.HibernateDAO;
import br.com.linkideias.model.dao.InterfaceDAO;
import br.com.linkideias.util.HibernateUtil;

public class ConsultarPcc implements InterfaceCommand {

	@Override
	public String execute(HttpServletRequest request,
			HttpServletResponse response) {
		
		Aluno aluno = null;
		
		InterfaceDAO<Estatus> estatusDAO = new HibernateDAO<Estatus>(Estatus.class, (Session)request.getAttribute(HibernateUtil.HIBERNATE_SESSION));
		request.getSession().setAttribute("estatuses", estatusDAO.getBeans());
		InterfaceDAO<Categoria> categoriaDAO = new HibernateDAO<Categoria>(Categoria.class, (Session)request.getAttribute(HibernateUtil.HIBERNATE_SESSION));
		request.getSession().setAttribute("categorias", categoriaDAO.getBeans());
		
		InterfaceDAO<Pcc> pccDAO = new HibernateDAO<Pcc>(Pcc.class, (Session)request.getAttribute(HibernateUtil.HIBERNATE_SESSION));
		aluno = (Aluno) request.getSession().getAttribute("aluno");
		System.out.println(aluno.getNome());
		
		List<Pcc> pccs= pccDAO.getPccAluno(aluno);
		
		for(Pcc p: pccs){
			System.out.println(p.getNome());
		}
		request.setAttribute("pccs", pccs);
		return "alunoPcc.jsp";
	}
}
